package com.gm.camunda.service.impl;

import com.gm.camunda.service.ProcessInstanceService;
import org.camunda.bpm.engine.IdentityService;
import org.camunda.bpm.engine.RuntimeService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * {@code @Author}: zhang liang
 * {@code @Date}: 2022/10/9 17:01
 * {@code @BelongsProject}: gm
 * {@code @BelongsPackage}: com.gm.camunda.service.impl
 * {@code @Description}: 流程实例实现
 */
public class ProcessInstanceServiceImpl implements ProcessInstanceService {

    private final RuntimeService runtimeService;

    private final IdentityService identityService;

    public ProcessInstanceServiceImpl(RuntimeService runtimeService, IdentityService identityService) {
        this.runtimeService = runtimeService;
        this.identityService = identityService;
    }


    @Override
    public void startProcessInstanceByKey(String processDefinitionKey, String businessKey, String initiator) {
        Map<String, Object> map = new HashMap<>(5);
        map.put("user1", "user1");
        map.put("user2", "user2");
        map.put("user3", "user3");
        //设置流程发起人
        identityService.setAuthenticatedUserId(initiator);
        runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, map);
    }
}
